package com.itheima.HomeWork_day10;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapTest05 {
    public static void main(String[] args) {
        // 创建TreeMap集合对象
        TreeMap<Student,String> tm = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge() - o2.getAge();
               result= result==0?o1.getName().compareTo(o2.getName()):result;
               return result;
            }
        });

        //添加元素
        tm.put(new Student("gang",21),"西安");
        tm.put(new Student("chen",21),"四川");
        tm.put(new Student("ming",21),"上海");
        tm.put(new Student("liu",21),"北京");

        //遍历集合
        tm.forEach((Student key,String value)->{
            System.out.println(key+"--"+value);
        });
    }
}
